import React from 'react';
import CommonList from '../../../../components/CommonLists/list';
import { Button, message } from 'antd';
import services from '../../../../services/api';
import Modal from '../../../../components/Modal/index';

class FieldList extends CommonList {
  constructor(props) {
    super(props);
    this.api = 'model';
    this.state = {
      applications: [],
      events: []
    };
    this.operatorWidth = '200px';
    this.editButton = record => {
      return (
        <Button
          size='small'
          type='link'
          onClick={this.props.detail && this.props.detail.bind(this, record, { title: '参数详情' })}
          disabled={record.audit_status === this.AUDIT._WAIT}
        >
          参数详情
        </Button>
      );
    };
    this.mapButton = record => {
      return (
        <Button
          size='small'
          type='link'
          onClick={this.props.map && this.props.map.bind(this, record)}
          disabled={record.audit_status === this.AUDIT._WAIT}
        >
          映射
        </Button>
      );
    };
    this.delButton = record => {
      return (
        <Button
          size='small'
          type='link'
          onClick={this.delete.bind(this, record)}
          disabled={record.audit_status === this.AUDIT._WAIT}
        >
          删除
        </Button>
      );
    };
    this.btnGroup = [this.editButton, this.mapButton, this.delButton];
  }

  // 删除时的参数
  getDeleteParam = record => {
    return { model_list_id: record.model_list_id };
  };

  delete(record) {

    Modal.open({
      title: '',
      isConfirm: true,
      width: '300px',
      content: '确定要删除?',
      isOkBtn: true,
      isCancelBtn: true,
      ok: () => {
        services[this.api].delete(this.getDeleteParam(record)).then(data => {
          if (data.code === 0) {
            message.success(data.msg);
            this.props.queryList();
            Modal.close();
          } else {
            message.error(data.msg);
          }
        });
      },
      cancel: () => {
        Modal.close();
      }
    });
  }
}

export default FieldList;
